<template>
  <div id="QuestionExplain">
    <a-tab-pane class="customTabPane" title="做题步骤">
      <a-card v-if="notice" :title="notice.title" class="centerCard">
        <MdView :value="notice.content || ''" class="customContent" />
      </a-card>
    </a-tab-pane>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";

import MdView from "@/components/MdView.vue";
import { NoticeVO } from "@/views/Home/NoticeVO";

const notice = ref<NoticeVO>();
// 直接给notice赋值
notice.value = {
  title: "题目说明",
  content:
    "### 题目说明\n" +
    "\n" +
    "本系统中所有的题目均来源于网络中，包括题解，输入输出用例等，如有雷同，请您见谅\n" +
    "\n" +
    "#### 1、判题条件\n" +
    "\n" +
    "判题条件分别为时间限制与内存限制（堆栈限制暂未实现），不满足任意条件即为出错\n" +
    "\n" +
    "##### （1）时间限制\n" +
    "\n" +
    "从代码提交的一刻开始计时，知道代码沙箱返回结果到数据库为一个计时时间，随后将结果查询反馈到系统中\n" +
    "\n" +
    "**注意**：Java代码的时间限制一般应设置较长，因为是面向对象的语言，需要的步骤较多，包括存储用户，编译，运行，输出结果等\n" +
    "\n" +
    "##### （2）内存限制\n" +
    "\n" +
    "同上述时间限制条件，不过在获取内存限制的时候采取了两种形式\n" +
    "\n" +
    "第一种：**Java原生**内存获取方法，即采用封装好的Java方法进行获取运行内存\n" +
    "\n" +
    "```java\n" +
    "public static long getProcessMemoryUsage(Process process) throws IOException {\n" +
    "    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();\n" +
    "    MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage();\n" +
    "    MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage();\n" +
    "    long heapMemoryUsed = heapMemoryUsage.getUsed() / (1024 * 1024); // Convert to MB\n" +
    "    long nonHeapMemoryUsed = nonHeapMemoryUsage.getUsed() / (1024 * 1024); // Convert to MB\n" +
    "    return heapMemoryUsed + nonHeapMemoryUsed;\n" +
    "}\n" +
    "```\n" +
    "\n" +
    "第二种：**Docker容器**获取内存，采用远程连接虚拟机的方式进行开发，通过拉取，运行Docker Java镜像，在容器中进行代码沙箱操作，来获取运行内存\n" +
    "\n" +
    "```java\n" +
    "//获取占用内存\n" +
    "StatsCmd statsCmd = dockerClient.statsCmd(containerId);\n" +
    "ResultCallback<Statistics> statisticsResultCallback = statsCmd.exec(new ResultCallback<Statistics>() {\n" +
    "    @Override\n" +
    "    public void close() throws IOException {\n" +
    "\n" +
    "    }\n" +
    "\n" +
    "    @Override\n" +
    "    public void onStart(Closeable closeable) {\n" +
    "\n" +
    "    }\n" +
    "\n" +
    "    @Override\n" +
    "    public void onNext(Statistics statistics) {\n" +
    '        System.out.println("内存占用：" + statistics.getMemoryStats().getUsage());\n' +
    "        maxMemory[0] = Math.max(statistics.getMemoryStats().getUsage(), maxMemory[0]);\n" +
    "    }\n" +
    "\n" +
    "    @Override\n" +
    "    public void onError(Throwable throwable) {\n" +
    "\n" +
    "    }\n" +
    "\n" +
    "    @Override\n" +
    "    public void onComplete() {\n" +
    "\n" +
    "    }\n" +
    "});\n" +
    "statsCmd.exec(statisticsResultCallback);\n" +
    "```\n" +
    "\n" +
    "#### 2、输入，输出用例\n" +
    "\n" +
    "代码沙箱会根据系统设置好的输入输出用例进行代码测试，即将输入用例代进用户编写的程序中，得到用户的输出用例，将其与系统设置好的输出用例进行比对，包括输出数量，是否正确等\n" +
    "\n" +
    "```java\n" +
    "// 最先判断沙箱执行的结果中的程序执行信息是否为空\n" +
    "if (judgeInfoResponse.getMessage() != null) {\n" +
    "    return judgeInfoResponse;\n" +
    "}\n" +
    "\n" +
    "// 先判断沙箱执行的结果输出数量是否和预期输出数量相等\n" +
    "if (outputList.size() != inputList.size()) {\n" +
    "    judgeInfoMessageEnum = JudgeInfoMessageEnum.OUTPUT_LIMIT_EXCEEDED;\n" +
    "    judgeInfoResponse.setMessage(judgeInfoMessageEnum.getValue());\n" +
    "    return judgeInfoResponse;\n" +
    "}\n" +
    "// 依次判断每一项输出和预期输出是否相等\n" +
    "for (int i = 0; i < judgeCaseList.size(); i++) {\n" +
    "    JudgeCase judgeCase = judgeCaseList.get(i);\n" +
    '    Pattern pattern = Pattern.compile("\\\\d+(\\\\.\\\\d+)?");\n' +
    "    Matcher matcher1 = pattern.matcher(outputList.get(i));\n" +
    "    Matcher matcher2 = pattern.matcher(judgeCase.getOutput());\n" +
    "    List<Double> output = new ArrayList<>();\n" +
    "    while (matcher1.find()) {\n" +
    "        String numberStr = matcher1.group();\n" +
    "        double number = Double.parseDouble(numberStr);\n" +
    "        output.add(number);\n" +
    "    }\n" +
    "    List<Double> judgeCaseOutPut = new ArrayList<>();\n" +
    "    while (matcher2.find()) {\n" +
    "        String numberStr = matcher2.group();\n" +
    "        double number = Double.parseDouble(numberStr);\n" +
    "        judgeCaseOutPut.add(number);\n" +
    "    }\n" +
    "    if (!judgeCaseOutPut.equals(output)) {\n" +
    "        judgeInfoMessageEnum = JudgeInfoMessageEnum.WRONG_ANSWER;\n" +
    "        judgeInfoResponse.setMessage(judgeInfoMessageEnum.getValue());\n" +
    "        return judgeInfoResponse;\n" +
    "    }\n" +
    "}\n" +
    "```\n" +
    "\n" +
    "#### 3、注意\n" +
    "\n" +
    "只贴出核心代码片段，具体详见源程序\n" +
    "\n",
};
</script>

<style>
#QuestionExplain {
  max-width: 1200px;
  margin: 0 auto;
}
.centerCard {
  font-size: 18px; /* 调整内容文字大小为16px */
}
.customContent {
  font-size: 18px; /* 调整内容文字大小为16px */
}

#viewQuestionView .arco-space-horizontal .arco-space-item {
  margin-bottom: 0 !important;
}
</style>
